package com.dengc;

import java.awt.*;

public class Bg {
    Image bg = Toolkit.getDefaultToolkit().getImage("imgs/bg.jpg");
    Image bg1 = Toolkit.getDefaultToolkit().getImage("imgs/bg1.jpg");
    Image peo = Toolkit.getDefaultToolkit().getImage("imgs/peo.png");

    Image water = Toolkit.getDefaultToolkit().getImage("imgs/water.png");
    //总积分
    static int count = 0;

    //药水数量
    static int waterNum = 3;

    //药水装填,默认false ，true使用
    static  boolean waterFlag = false;

    //关卡数
    static int level = 1;
    //目标得分
    int goal = level * 15;
    //开始时间
    long startTime;
    //结束时间
    long endTime;
    //药水价格
    int price = (int) (Math.random()*10);
    //是否进入商店
    boolean shop = false;

    void  paintSelf(Graphics g){
        g.drawImage(bg,0,200,null);
        g.drawImage(bg1,0,0,null);
        switch (GameWin.state){
            case 0:
                drawString(g,80,Color.green,"右击屏幕开始游戏",60,400);
                break;
            case 1:
                g.drawImage(peo,310,50,null);
                //绘制字符串
                drawString(g,30,Color.black,"分数:"+count,30,150);
                //药水绘制
                g.drawImage(water,620,40,null);
                drawString(g,30,Color.black,"*:"+waterNum,700,70);
                //关卡数
                drawString(g,20,Color.black,"第"+level+"关",30,60);
                //目标积分
                drawString(g,30,Color.black,"目标分数:"+goal,30,110);
                endTime = System.currentTimeMillis();
                long tim = 20 - (endTime-startTime)/1000;
                //打印倒计时
                drawString(g,30,Color.black,"剩余时间："+(tim>0 ? tim : 0),520,150);
                break;
            case 2:
                //药水绘制
                g.drawImage(water,300,400,null);
                drawString(g,30,Color.black,"价格:"+price,300,500);
                drawString(g,30,Color.black,"是否购买？"+waterNum,300,550);
                if (shop){
                    count = count - price;
                    waterNum++;
                    shop = false;
                    GameWin.state = 1;
                    startTime = System.currentTimeMillis();
                }
                break;
            case 3:
                drawString(g,80,Color.red,"失败！",300,450);
                drawString(g,80,Color.red,"分数:"+count,250,550);
                break;
            case 4:
                drawString(g,80,Color.green,"成功！",300,450);
                drawString(g,80,Color.green,"分数:"+count,250,550);
                break;
            default:
        }

    }

    boolean gameTime(){
        long tim = (endTime - startTime)/1000;
        if (tim > 20) return true;
        else return false;
    }

    void reGame(){
        //总积分
        count = 0;

        //药水数量
        waterNum = 3;

        //药水装填,默认false ，true使用
        waterFlag = false;

        //关卡数
        level = 1;
        //目标得分
        goal = level * 15;
    }

    //绘制字符串方法
    public static void  drawString(Graphics g,int size,Color color, String str,int x, int y){
        g.setColor(color);
        g.setFont(new Font("仿宋",Font.BOLD,size));
        g.drawString(str,x,y);
    }

}
